﻿@{
    Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
}
@section ScriptAndCss{
    <link href="@Url.Content("~/Content/css/plan.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/plan.js")" type="text/javascript"></script>
}
<div class="padding5" id="groupList">
    <table id="MyGroupList" style="height: 350px;" class="" title="计划任务组" pagination="true" url="/PlanManagement/GetAllGroup"
        fitcolumns="true" singleselect="true">
        <thead>
            <tr>
                <th field="ID" sortable="true" width="180">计划编号</th>
                <th field="GroupName" sortable="true" width="140">计划任务组名称</th>
                <th field="CreatorName" sortable="true" width="100">创建人</th>
                <th field="CreateTime" sortable="true" formatter="DateFormate" width="100">创建时间</th>
                <th field="Ope" width="100" formatter="OpeRender">操作</th>
            </tr>
        </thead>
    </table>
</div>
<div class="padding5">
    计划任务组名称：<input type="text" id="groupName" />
    <input type="button" value="添加" onclick="addGroup();" />
</div>

<script type="text/javascript">
    var DateFormate = function (value, row, index) {
        if (value) {
            return value.DateStringConvert('yyyy-MM-dd');
        }
    };

    var OpeRender = function (value, row, index) {
        if (row["GroupType"] == "2") {
            row["Ope"] = true;
            return '<a class="deleteRow">删除</a>';
        }
        return "";
    };

    var addGroup = function () {
        var groupName = $('#groupName').val();
        if (!groupName) { $.messager.alert('提醒', '<ul class="warnTip"><li>请填写计划任务组名称!</li></ul>', 'warning'); return false; }

        $.post('/PlanManagement/SaveGroup', { groupName: groupName }, function (res) {
            if (res == "OK") {
                $.messager.alert('确认', '保存成功！', '', function () {
                    $('#MyGroupList').datagrid('reload');
                });
            }
            if (res == "Error") {
                $.messager.alert('错误', '保存失败!', 'error');
            }
        });
    };

    $(function () {
        $('#MyGroupList').datagrid({
            pageSize: 10,
            pageList: [10],
            pageNumber: 1,
            onDblClickRow: function (rowIndex, rowData) {
                var groupID = rowData["ID"];
                var rnd = (new Date()).getMilliseconds() + "" + parseInt(Math.random() * 10000);
                showModuleDialog('/PlanManagement/GroupUserList?GroupID=' + groupID + '&nocatch=' + rnd);
            },
            onClickCell: function (rowIndex, field, value) {
                if (field == "Ope" && value) {
                    $.messager.confirm('提醒', '确认删除这个组吗？', function (r) {
                        if (r) {
                            $.post('/PlanManagement/DeleteGroup', {
                                ID: $('#MyGroupList').datagrid('getData').rows[rowIndex]["ID"]
                            }, function (res) {
                                if (res == "OK") {
                                    $.messager.alert('提示', '删除成功!', 'info', function () {
                                        $('#MyGroupList').datagrid('reload');
                                    });
                                }
                                if (res == "Error") {
                                    $.messager.alert('错误', '删除失败!', 'error');
                                }
                            });
                        }
                    });
                }
            }
        });

        var p1 = $('#MyGroupList').datagrid('getPager');
        $(p1).pagination({
            beforePageText: '第',
            afterPageText: '页&nbsp;共&nbsp;{pages}&nbsp;页',
            displayMsg: '当前显示{from} - {to}&nbsp;条记录&nbsp;共&nbsp;{total}&nbsp;条记录'

        });
    });
</script>

